import {
  Column,
  Entity,
  PrimaryGeneratedColumn,
  CreateDateColumn,
  UpdateDateColumn,
  ManyToOne,
  JoinColumn
} from 'typeorm';
import { BaseEntity } from 'src/common/entities/base';
import { ApiProperty } from '@nestjs/swagger';
import {ProfessionalEntity} from "../../professional/entities/professional.entity";
import {SchoolEntity} from "../../school/entities/school.entity";
import {CampusEntity} from "../../campus/entities/campus.entity";
import {ClassEntity} from "../../class/entities/class.entity";
import {CLIENT_USER_TYPE} from "../../../../common/constant";

@Entity('edu_student', {
  comment: '学生表',
})
export class StudentEntity extends BaseEntity {
  @PrimaryGeneratedColumn({ type: 'int', name: 'student_id', comment: '学生ID' })
  public studentId: number;

  @Column({ type: 'varchar', length: 64, unique: true, nullable: true }) // 前台注册必填，后台可为空
  public username: string;

  @Column({ type: 'varchar', length: 255, nullable: true }) // 密码加密后存储
  public password: string;

  @Column({ type: 'varchar', length: 32, nullable: true }) // 加密盐值
  public salt: string;

  @Column({
    type: 'varchar',
    default: CLIENT_USER_TYPE.STUDENT,
  })
  public userType: string; // 区分来源

  @Column({ type: 'boolean', default: true }) // 是否允许登录
  public loginEnabled: boolean;

  @ApiProperty({ description: '学生姓名' })
  @Column({ type: 'varchar', name: 'student_name', length: 30,  default:null,  comment: '学生姓名' })
  public studentName: string;

  @ApiProperty({ description: '邮箱' })
  @Column({ type: 'varchar', length: 255, nullable: true, comment:'邮箱' })
  public email: string;

  @ApiProperty({ description: '曾用名' })
  @Column({ type: 'varchar', name: 'old_name', length: 30,  default:null,  comment: '曾用名' })
  public oldName: string;

  @ApiProperty({ description: '性别' })
  @Column({ type: 'char', name: 'gender', length: 2,  default:'1',  comment: '性别' })
  public gender: string;

  @ApiProperty({ description: '身份证号码' })
  @Column({ type: 'varchar', name: 'id_card', length: 30,  default:null, comment: '身份证号码' })
  public idCard: string;

  @ApiProperty({ description: '学生学号' })
  @Column({ type: 'varchar', name: 'student_number',  default:null, length: 64, comment: '学号' })
  public studentNumber: string;

  @ApiProperty({ description: '联系电话' })
  @Column({ type: 'varchar',  unique: true, name: 'phone', length: 64, comment: '联系电话' })
  public phone: string;

  @ApiProperty({ description: '学生状态' })
  @Column({ type: 'varchar', name: 'state',  default:null, comment: '学生状态' })
  public state: string;

  @ApiProperty({ description: '归属学校' })
  @Column({ type: 'int', name: 'school_id',  default:null, comment: '归属学校' })
  public schoolId: number;

  @ApiProperty({ description: '归属专业' })
  @Column({ type: 'int', name: 'pro_id',  default:null, comment: '归属专业' })
  public proId: number;

  @ApiProperty({ description: '归属班级' })
  @Column({ type: 'int', name: 'class_id', default:null,  comment: '归属班级' })
  public classId: number;

  @ApiProperty({ description: '归属校区' })
  @Column({ type: 'int', name: 'campus_id', default:null,  comment: '归属校区' })
  public campusId: number;

  @ApiProperty({ description: '出生年月' })
  @Column({ type: 'varchar', name: 'birthday',  default:null, comment: '归属校区' })
  public birthday: string;

  @ApiProperty({ description: '户籍地址' })
  @Column({ type: 'varchar', name: 'card_address', default:null, comment: '户籍地址' })
  public cardAddress: string;

  @ApiProperty({ description: '现居住地址' })
  @Column({ type: 'varchar', name: 'house_address', default:null, comment: '现居住地址' })
  public houseAddress: string;

  @ApiProperty({ description: '紧急联系人信息' })
  @Column({ type: 'text', name: 'emergency', nullable:true, comment: '紧急联系人' })
  public emergency: string;

  @ManyToOne(() => ProfessionalEntity, professional => professional.proId)
  @JoinColumn({ name: 'pro_id' })
  public professional: ProfessionalEntity;

  @ManyToOne(() => SchoolEntity, school => school.schoolId)
  @JoinColumn({ name: 'school_id' })
  public school: SchoolEntity;

  @ManyToOne(() => CampusEntity, campus => campus.campusId)
  @JoinColumn({ name: 'campus_id' })
  public campus: CampusEntity;

  @ManyToOne(() => ClassEntity, classz => classz.classId)
  @JoinColumn({ name: 'class_id' })
  public classz: ClassEntity;

}
